package com.lengyue.imakiba.manage;

import java.util.HashMap;
import java.util.Map;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.lengyue.imakiba.data.Episode;

public class EpisodeManage extends Controller {
	public void getEpisode()
	{
		int animeId = 0;
		try {
			animeId = getParaToInt("animeId");
		} catch (Exception e) {
		}
		Page<Episode> episodes = Episode.dao.paginate(getParaToInt("page"), getParaToInt("rows"),"select * ","from episode where anime_id = ? order by num desc",animeId);
		long total = Episode.dao.find("select count(id) total from episode where anime_id = ?",animeId).get(0).getLong("total");
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		jsonMap.put("total", total);
		jsonMap.put("rows", episodes.getList());
		renderJson(jsonMap);
	}
	public void saveEpisode()
	{
		new Episode().set("num", getPara("num")).set("name", getPara("name")).set("anime_id", getPara("anime_id"))
		.set("url1", getPara("url1")).set("url2", getPara("url2")).set("url3", getPara("url3"))
		.set("url4", getPara("url4")).set("url5", getPara("url5")).set("url6", getPara("url6"))
		.set("date", getPara("date")).save();
	}
	public void updateEpisode()
	{
		Episode.dao.findById(getPara("id")).set("num", getPara("num")).set("name", getPara("name")).set("anime_id", getPara("anime_id"))
		.set("url1", getPara("url1")).set("url2", getPara("url2")).set("url3", getPara("url3"))
		.set("url4", getPara("url4")).set("url5", getPara("url5")).set("url6", getPara("url6"))
		.set("date", getPara("date")).update();
	}
	public void deleteEpisode()
	{
		Episode.dao.deleteById(getPara("id"));
	}
}
